import { createSlice } from '@reduxjs/toolkit'

const initialState = {
 penple:[
    {
        name:'张三',
        tel:'15522223333',
        code:'410527200103060025',
    },
    {
        name:'李四',
        tel:'15522224444',
        code:'410527200103060026',
    },
    {
        name:'王五',
        tel:'15522225555',
        code:'410527200103060027',
    },
    {
        name:'赵六',
        tel:'15522226666',
        code:'410527200103060028',
    },
 ]
}

export const counterSlice = createSlice({
  name: 'counter',
  initialState,
  reducers: { 
    delPenple: (state, action) => {
      state.penple = state.penple.filter(item=>item.code!==action.payload)
    },
    addPenple:(state,action)=>{
        state.penple.push(action.payload)
    },
    enidPenple:(state,action)=>{
        state.penple = state.penple.map(item=>{
          if(item.code===action.payload.code){
            return action.payload
          }else{
            return item
          }
        })
    }
  },
})

// Action creators are generated for each case reducer function
export const { delPenple,addPenple ,enidPenple } = counterSlice.actions

export default counterSlice.reducer